import React from 'react'; import { NextPage, GetServerSideProps, GetServerSidePropsContext, } from 'next'; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useRouter } from 'next/router'; import { NoLoginLayout } from '~/components/Layout/NoLoginLayout'; import { CommonProps, getServerSideCommonProps, getNextI18NextConfig, } from '~/pages/utils/commons'; import { useCsrfToken, useCurrentPathname, } from '~/stores/context'; type Props = CommonProps; const LoginPage: NextPage = (props: CommonProps) => { // commons useCsrfToken(props.csrfToken); const { t } = useTranslation(); const router = useRouter(); const { message } = router.query; // page useCurrentPathname(props.currentPathname); const classNames: string[] = ['login-page']; let loginErrorElm; const renderResistrationSuccessFul = () => { return ( <>

{ t('login.registration_successful') }

Wait for approved by administrators.

); }; const renderSuspendedUserError = () => { return ( <>

{ t('login.sign_in_error') }

This account is suspended.

); }; const renderPasswordResetOrderError = () => { return ( <>

{ t('forgot_password.incorrect_token_or_expired_url') }

{ t('forgot_password.forgot_password') } ); }; const renderDefaultLoginError = () => { return (

{ t('login.sign_in_error') }

); }; switch (message) { case 'registered': loginErrorElm = () => renderResistrationSuccessFul(); break; case 'suspended': loginErrorElm = () => renderSuspendedUserError(); break; case 'password-reset-order': loginErrorElm = () => renderPasswordResetOrderError(); break; default: loginErrorElm = () => renderDefaultLoginError(); } return (
{loginErrorElm()}
{/* If the transition source is "/login", use tag since the transition will not occur if next/link is used. */} {t('Sign in is here')}
); }; /** * for Server Side Translations * @param context * @param props * @param namespacesRequired */ async function injectNextI18NextConfigurations(context: GetServerSidePropsContext, props: Props, namespacesRequired?: string[] | undefined): Promise { const nextI18NextConfig = await getNextI18NextConfig(serverSideTranslations, context, namespacesRequired); props._nextI18Next = nextI18NextConfig._nextI18Next; } export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => { const result = await getServerSideCommonProps(context); // check for presence // see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862 if (!('props' in result)) { throw new Error('invalid getSSP result'); } const props: Props = result.props as Props; await injectNextI18NextConfigurations(context, props, ['translation']); return { props, }; }; export default LoginPage;